package com.liang.controller;/*
 *@Author: ljy
 *@Date:2021/11/6 16:42
 *
 */

import com.liang.service.EnclosureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/Enclosure")
@Slf4j
public class EnclosureController {
    @Autowired
    private EnclosureService enclosureService;

    /**
     * 附件上传
     *
     * @param file
     * @return
     */
    @PostMapping("/uploadEnclosure")
    public String uploadEnclosure(MultipartFile file) {
        return enclosureService.uploadEnclosure(file);
    }

    /**
     * 附件下载
     * @param id
     * @param response
     * @return
     */
    @GetMapping(value ={"/downLoadEnclosure/{eid}"})
    public String downLoadEnclosure(@PathVariable("eid") Integer id, HttpServletResponse response) {
        if (id != null) {
            return enclosureService.downloadEnclosure(id,response);
        }
        return  "文件不存在";
     }
}
